package com.cfl.shiro;

import java.lang.reflect.Array;
import java.util.ArrayList;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.config.IniSecurityManagerFactory;
import org.apache.shiro.mgt.SecurityManager;
import org.apache.shiro.subject.Subject;
import org.apache.shiro.util.Factory;

public class ShiroUsersRoles {
	
		@SuppressWarnings("unused")
		public static void main(String[] args) {

			Subject subject = ShiroUtil.login("classpath:shiro_users_roles.ini", "chenfenli", "123456");
			
			// 是否有某一个角色
			if(subject.hasRole("role1"))
			{
				System.out.println("有该角色");
			}
			else
			{
				System.out.println("无该角色");
			}
			
			// 返回角色集合
			ArrayList<String> arrayList = new ArrayList<String>();
			arrayList.add("role1");
			arrayList.add("role2");
			arrayList.add("role3");
			boolean[] bls = subject.hasRoles(arrayList);
			for (int i = 0; i < bls.length; i++) {
				System.out.println(bls[i]);
			}
			
			// 是否包含所有角色
			ArrayList<String> arrayList2 = new ArrayList<String>();
			arrayList2.add("role1");
			arrayList2.add("role2");
			if(subject.hasAllRoles(arrayList2))
			{
				System.out.println("包含所有角色");
			}
			else
			{
				System.out.println("不包含所有角色");
			}
			
			// 是否有某一个权限
			if(subject.isPermitted("user:select"))
			{
				System.out.println("有此权限");
			}
			else
			{
				System.out.println("无此权限");
			}
			
			// 返回权限集合
			boolean[] bls2 = subject.isPermitted("user:select","user:add","user:update","user:delete","user:remove");
			for (int i = 0; i < bls2.length; i++) {
				System.out.println(bls2[i]);
			}
			
			// 是否包含所有权限
			if(subject.isPermittedAll("user:select","user:add","user:update","user:delete"))
			{
				System.out.println("包含所有权限");
			}
			else
			{	
				System.out.println("不包含所有权限");
			}
		}
}
